package com.shankar.narayan.ms.screen;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.InvalidParameterException;

public class TriangleType {

	private static Integer _a;

	private static Integer _b;

	private static Integer _c;

	// enum for triangle types.
	public enum Type {
		SCALENE, ISOCELES, EQUILATERAL, ERROR;

		int getType() {
			return this.ordinal() + 1;
		}

	}

	public static int getTriangleType(String a, String b, String c) {
		try {
			// a,b and c are the three sides of the triangle.
			if (a == null || b == null || c == null) {
				String error = "Must specify all three sides of the triangle";
				throw new InvalidParameterException(error);
			}

			_a = Integer.parseInt(a);
			_b = Integer.parseInt(b);
			_c = Integer.parseInt(c);
		} catch (Exception exp) {
			return Type.ERROR.getType();
		}

		if (_a == _b && _b == _c) {
			return Type.EQUILATERAL.getType();
		} else if (_a == _b || _b == _c || _a == _c) {
			return Type.ISOCELES.getType();
		} else if (_a != _b && _b != _c && _c != _a) {
			return Type.SCALENE.getType();
		} else {
			return Type.ERROR.getType();
		}
	}

	public static void main(String[] args) {

		String _side_a;
		String _side_c;
		String _side_b;

		System.out.println("Enter side 1 dimension of the Triangle:");
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		try {
			_side_a = reader.readLine();
			System.out.println("Enter side 2 dimension of the Triangle:");
			reader = new BufferedReader(new InputStreamReader(System.in));
			_side_b = reader.readLine();
			System.out.println("Enter side 3 dimension of the Triangle:");
			reader = new BufferedReader(new InputStreamReader(System.in));
			_side_c = reader.readLine();
			System.out.println("The type of the triangle is = "
					+ getTriangleType(_side_a, _side_b, _side_c));
		} catch (IOException e) {
			System.out.println("Error occured: IOException");
		}
	}
}
